package com.anjubao.parking.municipal.parkinglot.service;

import cn.hutool.core.date.DateUtil;
import com.anjubao.parking.municipal.parkinglot.dto.ParkingStatRecordsResDto;
import com.anjubao.parking.municipal.parkinglot.dto.ParkingStatRecordsZonesResDto;
import com.anjubao.parking.municipal.parkinglot.dto.ParkingTrentRecordsResDto;
import com.anjubao.parking.municipal.parkinglot.mapper.ParkingStatRecordMapper;
import com.anjubao.parking.municipal.parkinglot.model.ParkingStatRecord;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.Date;
import java.util.List;

/**
 * ParkingStatRecord服务实现类
 * 
 * @author anjubao
 */
@Service
@Slf4j
public class ParkingStatRecordService extends ServiceImpl<ParkingStatRecordMapper, ParkingStatRecord> {

	@Autowired
	private ParkingStatRecordMapper parkingStatRecordMapper;

	/**
	 * 根据城市id和停车场类型统计当日各类型停车场停车记录总数
	 * 
	 * @param cityId
	 * @param type
	 * @param startTime
	 * @param endTime
	 * @return
	 */
	public List<ParkingStatRecordsResDto> findStatRecords(Integer cityId, Integer type, LocalDateTime startTime,LocalDateTime endTime) {
		return parkingStatRecordMapper.findStatRecords(cityId, type, startTime,endTime);
	}

	/**
	 * 根据城市id和市区Id统计当日各区域车流量
	 * 
	 * @param cityId
	 * @param districtId
	 * @return
	 */
	public List<ParkingStatRecordsZonesResDto> findZonesRecords(Integer cityId, Integer districtId) {
		return parkingStatRecordMapper.findZonesRecords(cityId, districtId);
	}

	/**
	 * 根据城市id和市区Id统计分时停车场趋势
	 * 
	 * @param cityId
	 * @param type
	 * @return
	 */
	public List<ParkingTrentRecordsResDto> getParkingTrendRecords(Integer cityId, Integer type) {
		String hour = DateUtil.format(new Date(), "HH");
		log.debug("new Date():" + new Date() + "|" + hour);
		if (hour.equals(0)) {
			return parkingStatRecordMapper.getParkingTrendRecords(cityId, type, 0);
		}
		return parkingStatRecordMapper.getParkingTrendRecords(cityId, type, Integer.valueOf(hour) - 1);
	}

	public static void main(String[] args) {
		System.out.println(DateUtil.format(new Date(), "HH"));
	}

}
